<template>
    <div class="app-container">
        <div class="head-container">
            <!-- 搜索 -->
            <table>
                <tr>
                    <td>关联项目:</td>
                    <td>
                        <el-input v-model="listQuery.markedness" clearable size="small" style="width: 200px;"
                            class="filter-item" @keyup.enter.native="handleFilter" />
                    </td>
                    <td>单据主题:</td>
                    <td>
                        <el-input v-model="listQuery.theme" clearable size="small" style="width: 200px;"
                            class="filter-item" @keyup.enter.native="handleFilter" />
                    </td>

                    <td>单据编码:</td>
                    <td>
                        <el-input v-model="listQuery.serialNumber" clearable size="small" style="width: 200px;"
                            class="filter-item" @keyup.enter.native="handleFilter" />
                    </td>

                    <td>添加人员:</td>
                    <td>
                        <el-input v-model="listQuery.pricing" clearable size="small" style="width: 200px;"
                            class="filter-item" @keyup.enter.native="handleFilter" />
                    </td>
                </tr>
                <tr>
                    <td>日期:</td>
                    <td>
                        <el-date-picker type="date" placeholder="开始日期" v-model="listQuery.startDate"
                            style="width: 184px;">
                        </el-date-picker>

                    </td>
                    <td>
                        <el-date-picker type="date" placeholder="结束日期" v-model="listQuery.endDate"
                            style="width: 184px;">
                        </el-date-picker>
                    </td>
                    <el-button class="filter-item" size="mini" type="success" icon="el-icon-search"
                        @click="handleFilter">搜索
                    </el-button>
                </tr>
            </table>
            <div style="padding: 6px 0">
                <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="handleCreate">新增
                </el-button>
                <el-button class="filter-item" size="mini" type="success" icon="el-icon-edit" @click="handleUpdate()">修改
                </el-button>
                <el-button slot="reference" class="filter-item" type="danger" icon="el-icon-delete" size="mini"
                    @click="handleDelete()">删除</el-button>
                <el-button class="filter-item" type="warning" icon="el-icon-s-check" size="mini"
                    @click="handleCheck()">审核</el-button>
            </div>
        </div>
        <!-- 新增 -->
        <el-dialog :visible.sync="dialogFormVisible" :close-on-click-modal="false" @close="cancel()" :title="formTitle"
            width="1400px" border>
            <el-form ref="form" :model="form" :rules="rules" size="medium" label-width="110px">
                <table>
                    <tr>
                        <!-- 第一列 -->
                        <td>
                            <el-form-item label="来源单据类型" prop="receiptsType">
                                <el-select v-model="form.receiptsType" placeholder="来源单据类型" style="width: 184px;">
                                    <el-option label="无来源" value="无来源"></el-option>
                                    <el-option label="报价申请" value="报价申请"></el-option>
                                    <el-option label="采购申请" value="采购申请"></el-option>
                                    <el-option label="项目档案" value="项目档案"></el-option>
                                </el-select>
                            </el-form-item>

                            <el-form-item label="定价人员" prop="pricing">
                                <el-input v-model="form.pricing" placeholder="部门" clearable
                                    style="width: 184px;"></el-input>
                            </el-form-item>
                        </td>

                        <!-- 第二列 -->
                        <td>
                            <el-form-item label="来源单据" prop="source">
                                <el-input v-model="form.source" placeholder="来源单据" clearable style="width: 184px;">
                                </el-input>
                            </el-form-item>

                            <el-form-item label="询价日期" prop="enquiry">
                                <el-date-picker v-model="form.enquiry" align="right" type="date" placeholder="询价日期"
                                    :picker-options="pickerOptions" style="width: 184px;">
                                </el-date-picker>
                            </el-form-item>

                        </td>

                        <!-- 第三列 -->
                        <td>
                            <el-form-item label="单据主题" prop="theme">
                                <el-input v-model="form.theme" placeholder="单据主题" clearable style="width: 184px;">
                                </el-input>
                            </el-form-item>

                            <el-form-item label="询价人员" prop="personnel">
                                <el-input v-model="form.personnel" placeholder="询价人员" clearable style="width: 184px;">
                                </el-input>
                            </el-form-item>

                        </td>

                        <!-- 第四列 -->
                        <td>

                            <el-form-item label="单据编号" prop="serialNumber">
                                <el-input v-model="form.serialNumber" placeholder="单据编号" clearable
                                    style="width: 184px;">
                                </el-input>
                            </el-form-item>

                            <el-form-item label="关联项目" prop="markedness">
                                <el-input v-model="form.markedness" placeholder="关联项目" clearable style="width: 184px;">
                                </el-input>
                            </el-form-item>
                        </td>
                    </tr>


                </table>
                <table>
                    <tr>
                        <el-form-item label="备注" prop="remark" style="width: 1190px;">
                            <el-input type="textarea" :rows="6" placeholder="请输入内容" v-model="form.remark">
                            </el-input>
                        </el-form-item>
                    </tr>
                </table>

            </el-form>
            <div>
                <el-button size="small" @click="addRow">增行</el-button>
            </div>
            <!--设置的表单-->
            <el-form :model="studentData" ref="data" label-width="auto">
                <el-table border :header-cell-style="{ 'text-align': 'center' }"
                    :cell-style="{ 'text-align': 'center' }" :data="studentData" ref="table" style="width: 100%">

                    <el-table-column align="center" label="产品名称">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.name'"
                                :rules="{ required: true, message: '产品名称不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].name" autocomplete="off" size="small"
                                    placeholder="产品名称"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="产品编码">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.name'"
                                :rules="{ required: true, message: '产品编码不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].name" autocomplete="off" size="small"
                                    placeholder="产品编码"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="规格型号">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.sex'"
                                :rules="{ required: true, message: '规格型号不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].sex" autocomplete="off" size="small"
                                    placeholder="规格型号"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="单位">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.name'"
                                :rules="{ required: true, message: '单位不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].name" autocomplete="off" size="small"
                                    placeholder="单位"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="数量">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '数量不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="数量"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="税率(%)">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '税率不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="税率"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="票据类型">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '票据类型不能为空', trigger: 'blur' }">
                                <el-select v-model="form.pname" placeholder="票据类型" style="width: 184px;">
                                    <el-option label="不开票" value="不开票"></el-option>
                                    <el-option label="增值税普通发票" value="增值税普通发票"></el-option>
                                    <el-option label="增值税专用发票" value="上海"></el-option>
                                </el-select>
                            </el-form-item>

                        </template>
                    </el-table-column>


                    <el-table-column align="center" label="折扣">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '折扣不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="折扣"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="未税折扣单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '未税折扣单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="未税折扣单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="含税单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '含税单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="含税单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="含税折后单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '含税折后单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="含税折后单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="未税金额">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '未税金额不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="未税金额"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="税额">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '税额不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="税额"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="总额">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.age'"
                                :rules="{ required: true, message: '总额不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].age" autocomplete="off" size="small"
                                    type='number' placeholder="总额"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>


                    <el-table-column align="center" label="交货日期">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.name'"
                                :rules="{ required: true, message: '交货日期不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].name" autocomplete="off" size="small"
                                    placeholder="交货日期"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="备注">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.name'"
                                :rules="{ required: true, message: '备注不能为空', trigger: 'blur' }">
                                <el-input v-model="studentData[scope.$index].name" autocomplete="off" size="small"
                                    placeholder="备注"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column fixed="right" label="操作" width="100">
                        <template slot-scope="scope">
                            <el-button @click="handleDeleteRow(studentData[scope.$index])" type="text"
                                size="small">删除</el-button>
                        </template>
                    </el-table-column>

                </el-table>
            </el-form>


            <div>
                <el-button size="small" @click="addRowse">增行</el-button>
            </div>
            <!--设置的表单-->
            <el-form :model="studentDatas" ref="data" label-width="auto">
                <el-table border :header-cell-style="{ 'text-align': 'center' }"
                    :cell-style="{ 'text-align': 'center' }" :data="studentDatas" ref="table" style="width: 100%">

                    <el-table-column align="center" label="供应商名称">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.dstriName'"
                                :rules="{ required: true, message: '供应商名称不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].dstriName" autocomplete="off" size="small"
                                    placeholder="供应商名称"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="数量">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.dstriNumber'"
                                :rules="{ required: true, message: '数量不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].dstriNumber" autocomplete="off"
                                    size="small" type='number' placeholder="数量"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.dstriPrice'"
                                :rules="{ required: true, message: '单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].dstriPrice" autocomplete="off"
                                    size="small" type='number' placeholder="单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="税率(%)">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.dstriTaxrate'"
                                :rules="{ required: true, message: '单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].dstriTaxrate" autocomplete="off"
                                    size="small" type='number' placeholder="单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="票据类型">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.dstriType'"
                                :rules="{ required: true, message: '税率不能为空', trigger: 'blur' }">
                                <el-select v-model="studentDatas[scope.$index].dstriType">
                                    <el-option label="不开票" value="不开票"></el-option>
                                    <el-option label="增值税普通发票" value="增值税普通发票"></el-option>
                                    <el-option label="增值税专用发票" value="上海"></el-option>
                                </el-select>
                            </el-form-item>
                        </template>
                    </el-table-column>



                    <el-table-column align="center" label="折扣">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.dstriDiscount'"
                                :rules="{ required: true, message: '折扣不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].dstriDiscount" autocomplete="off"
                                    size="small" type='number' placeholder="折扣"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="未税折扣单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.untaxedprice'"
                                :rules="{ required: true, message: '未税折扣单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].untaxedprice" autocomplete="off"
                                    size="small" type='number' placeholder="未税折扣单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="含税单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.taxincluded'"
                                :rules="{ required: true, message: '含税单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].taxincluded" autocomplete="off"
                                    size="small" type='number' placeholder="含税单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="含税折后单价">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.unitprice'"
                                :rules="{ required: true, message: '含税折后单价不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].unitprice" autocomplete="off" size="small"
                                    type='number' placeholder="含税折后单价"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="未税金额">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.untaxedamount'"
                                :rules="{ required: true, message: '未税金额不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].untaxedamount" autocomplete="off"
                                    size="small" type='number' placeholder="未税金额"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="税额">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.theamount'"
                                :rules="{ required: true, message: '税额不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].theamount" autocomplete="off" size="small"
                                    type='number' placeholder="税额"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="总额">
                        <template slot-scope="scope">
                            <el-form-item :prop="scope.$index + '.sumPrice'"
                                :rules="{ required: true, message: '总额不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].sumPrice" autocomplete="off" size="small"
                                    type='number' placeholder="总额"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>


                    <el-table-column align="center" label="交货日期">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.deliverydate'"
                                :rules="{ required: true, message: '交货日期不能为空', trigger: 'blur' }">
                                <el-date-picker v-model="studentDatas[scope.$index].deliverydate" align="right"
                                    type="date" placeholder="选择日期" :picker-options="pickerOptions"
                                    style="width: 184px;">
                                </el-date-picker>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column align="center" label="备注">
                        <template slot-scope="scope">
                            <!--表格里面嵌套表单-->
                            <el-form-item :prop="scope.$index + '.dstriRemark'"
                                :rules="{ required: true, message: '备注不能为空', trigger: 'blur' }">
                                <el-input v-model="studentDatas[scope.$index].dstriRemark" autocomplete="off"
                                    size="small" placeholder="备注"></el-input>
                            </el-form-item>
                        </template>
                    </el-table-column>

                    <el-table-column fixed="right" label="操作" width="100">
                        <template slot-scope="scope">
                            <el-button @click="handleDeleteRowse(studentDatas[scope.$index])" type="text"
                                size="small">删除</el-button>
                        </template>
                    </el-table-column>

                </el-table>
            </el-form>

            <div slot="footer">
                <el-button size="small" type="text" @click="cancel">取消</el-button>
                <el-button size="small" v-loading="formLoading" type="primary" @click="save">确认</el-button>
            </div>
        </el-dialog>

        <!-- 列表显示 -->
        <el-table ref="multipleTable" v-loading="listLoading" :data="list" size="small" style="width: 90%;"
            @sort-change="sortChange" @selection-change="handleSelectionChange" @row-click="handleRowClick">
            <el-table-column type="selection" width="44px"></el-table-column>
            <el-table-column label="单据主题" prop="theme" align="center" />
            <el-table-column label="单据编号" prop="serialNumber" align="center" />
            <el-table-column label="单据类型" prop="receiptsType" align="center" />
            <el-table-column label="关联项目" prop="markedness" align="center" />
            <el-table-column label="单据日期" prop="enquiry" align="center" />
            <el-table-column label="制单人员" prop="pricing" align="center" />

            <el-table-column label="操作" align="center">
                <template slot-scope="{row}">
                    <el-button type="primary" size="mini" @click="handleUpdate(row)" icon="el-icon-edit" />
                    <el-button type="danger" size="mini" @click="handleDelete(row)" icon="el-icon-delete" />
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="totalCount > 0" :total="totalCount" :page.sync="page" :limit.sync="listQuery.MaxResultCount"
            @pagination="getList" />
    </div>
</template>
<script>
import Pagination from "@/components/Pagination";
import permission from "@/directive/permission/index.js";
import { cloneDeep } from "lodash";

//添加数据
const defaultForm = {
    "receiptsType": "",
    "source": "",
    "theme": "",
    "serialNumber": "",
    "pricing": "",
    "enquiry": "",
    "personnel": "",
    "markedness": "",
    "remark": ""
}



export default {


    data() {
        return {

        };

    },

    name: 'Book',
    components: {
        Pagination
    },
    directives: {
        permission
    },
    props: [],
    data() {
        return {

            studentData: [],
            studentDatas: [],

            rules: {
                name: [{
                    required: true,
                    message: '请输入名称',
                    trigger: 'blur'
                }],
                description: [{
                    required: true,
                    message: '请输入描述',
                    trigger: 'blur'
                }],
                price: [{
                    required: true,
                    message: '价格',
                    trigger: 'blur'
                }],
            },
            form: Object.assign({}, defaultForm),
            list: [],
            totalCount: 0,
            listLoading: true,
            formLoading: false,
            listQuery: {
                theme: '',
                serialNumber: "",
                pricing: '',
                Sorting: '',
                markedness: '',
                SkipCount: 0,
                MaxResultCount: 10,
                EnquiryDate: '',
                startDate: '',
                endDate: ''
            },
            page: 1,
            dialogFormVisible: false,
            multipleSelection: [],
            formTitle: '',
            isEdit: false,
        }
    },
    computed: {},
    watch: {},
    created() {
        this.getList()
    },
    mounted() { },
    methods: {




        /**
         * 新增行
         */
        addRow() {
            let index = this.studentData.length;
            this.studentData.push({
                key: index,
                name: '',
                age: '',
                sex: '',
            });
        },

        addRowse() {
            let index = this.studentDatas.length;
            this.studentDatas.push({
                key: index,
                "dstriName": "",
                "dstriNumber": "",
                "dstriPrice": '',
                "dstriTaxrate": '',
                "dstriType": '',
                "dstriDiscount": '',
                "untaxedprice": '',
                "taxincluded": '',
                "unitprice": '',
                "untaxedamount": '',
                "theamount": '',
                "sumPrice": '',
                "deliverydate": "",
                "dstriRemark": ""
            });
        },

        /**
         * 删除行
         * @param row
         */
        handleDeleteRow(row) {
            let datas = this.studentData;
            for (var i = 0; i < datas.length; i++) {
                if (datas[i].key == row.key) {
                    datas.splice(i, 1);
                }
            }
        },

        handleDeleteRowse(row) {
            let datas = this.studentDatas;
            for (var i = 0; i < datas.length; i++) {
                if (datas[i].key == row.key) {
                    datas.splice(i, 1);
                }
            }
        },

        /**
         * 提交
         */
        submit() {
            this.$refs["data"].validate(valid => {
                //valid为true，表示表单都已经验证通过，若为false，说明存在表单验证失败
                if (valid) {
                    save(this.studentData).then(response => {
                        this.$message({
                            message: '提交成功',
                            type: 'success'
                        });
                    });
                }
            });
        },

        /**
         * 重置
         */
        resetForm() {
            let datas = this.studentData;
            for (var i = 0; i < datas.length; i++) {
                datas[i].name = '';
                datas[i].age = '';
                datas[i].sex = '';
            }
        },


        // getListStatus(items, ids) {
        //     this.$axios.posts('api/business/workflow/node-status', ids).then(response => {
        //         items.forEach(element => { response.items.filter((i) => { if (i.entityId === element.id) { element.status = i.status; element.nodeId = i.nodeId; element.nodeStatus = i.nodeName } }) })
        //         this.list = items
        //         this.listLoading = false;
        //     });
        // },

        //显示方法
        getList() {
            //this.listLoading = true;
            this.listQuery.SkipCount = (this.page - 1) * this.listQuery.MaxResultCount;
            this.$axios.gets('/api/business/purch', this.listQuery).then(response => {
                this.totalCount = response.totalCount;
                this.list = response.items
                console.log(this.list);
                this.listLoading = false;
                //this.getListStatus(response.items, response.items.map(_ => _.sid))
            });
        },
        fetchData(id) {
            this.$axios.gets('/api/business/purch/' + id).then(response => {
                this.form = response;
            });
        },
        handleFilter() {
            this.page = 1;
            this.getList();
        },
        handleCreate() {
            this.formTitle = '采购文件';
            this.isEdit = false;
            this.dialogFormVisible = true;
        },
        handleDelete(row) {
            var params = [];
            let alert = '';
            if (row) {
                params.push(row.id);
                alert = row.sname;
            }
            else {
                if (this.multipleSelection.length === 0) {
                    this.$message({
                        message: '未选择',
                        type: 'warning'
                    });
                    return;
                }
                this.multipleSelection.forEach(element => {
                    let id = element.id;
                    params.push(id);
                    console.log(params);
                });

                console.log(params);
                alert = '选中项';
            }
            this.$confirm('是否删除' + alert + '?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$axios.posts('/api/business/purch/delete', params).then(response => {
                    this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    });
                    this.getList();
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        handleCheck() {
            if (this.multipleSelection.length === 0) {
                this.$message({
                    message: '未选择',
                    type: 'warning'
                });
                return;
            }
            if (this.multipleSelection.length > 1) {
                this.$message({
                    message: '暂不支持批量审核',
                    type: 'warning'
                });
                return;
            }
            this.$confirm('是否审核所选项?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$axios.puts('api/business/workflow/do/' + this.multipleSelection[0].id, { data: JSON.stringify(this.multipleSelection[0]) }).then(response => {
                    this.$notify({
                        title: '成功',
                        message: '审核成功',
                        type: 'success',
                        duration: 2000
                    });
                    this.getList();
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消审核'
                });
            });
        },
        findFlow(row) {
            this.$router.push({ path: "/tool/flowDisplay/" + row.nodeId });
        },
        handleUpdate(row) {
            this.formTitle = '修改图书';
            this.isEdit = true;
            if (row) {
                this.fetchData(row.id);
                this.dialogFormVisible = true;
            }
            else {
                if (this.multipleSelection.length != 1) {
                    this.$message({
                        message: '编辑必须选择单行',
                        type: 'warning'
                    });
                    return;
                }
                else {
                    this.fetchData(this.multipleSelection[0].id);
                    this.dialogFormVisible = true;
                }
            }
        },
        save() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    this.formLoading = true;
                    this.form.roleNames = this.checkedRole;
                    if (this.isEdit) {
                        this.$axios.posts('/api/business/purch/data-post', this.form).then(response => {
                            this.formLoading = false;
                            this.$notify({
                                title: '成功',
                                message: '更新成功',
                                type: 'success',
                                duration: 2000
                            });
                            this.dialogFormVisible = false;
                            this.getList();
                        }).catch(() => {
                            this.formLoading = false;
                        });
                    }
                    else {
                        this.$axios.posts('/api/business/purch/data-post', this.form).then(response => {
                            this.formLoading = false;
                            this.$notify({
                                title: '成功',
                                message: '新增成功',
                                type: 'success',
                                duration: 2000
                            });
                            this.dialogFormVisible = false;
                            this.getList();
                        }).catch(() => {
                            this.formLoading = false;
                        });
                    }
                }
            });

        },
        sortChange(data) {
            const {
                prop,
                order
            } = data;
            if (!prop || !order) {
                this.handleFilter();
                return;
            }
            this.listQuery.Sorting = prop + ' ' + order;
            this.handleFilter();
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            console.log(val);
        },
        handleRowClick(row, column, event) {
            this.$refs.multipleTable.clearSelection();
            this.$refs.multipleTable.toggleRowSelection(row);
        },
        cancel() {
            this.form = Object.assign({}, defaultForm);
            this.dialogFormVisible = false;
            this.$refs.form.clearValidate();
        },
    }
}

</script>
<style></style>

</script>
<style></style>
